var $ = getApp(), methods = require("../methods.js");
Page(Object.assign({},methods,{
	data: {
		st: 0,
		datalist: [],
		pagenum: 1,
		maskshow:false
	},
	_onLoad: function () {
		var that = this;
		$.get('ggk/myprize',{hid:that.options.hid},function(res){
			res.info.formcontent = JSON.parse(res.info.formcontent)
			that.setData(res)
		})
	},
	duijiang:function(e){
		var that = this
		var k = e.currentTarget.dataset.k
		var id = e.currentTarget.dataset.id
		var record = that.data.recordlist[k]
		var formdata = JSON.parse(record.formdata);
		console.log(formdata)
		that.setData({record:record,formdata:formdata,maskshow:true})
	},
	changemaskshow:function(){
		var that = this
		that.setData({maskshow:!that.data.maskshow})
	},
	formsub:function(e){
		var that = this
		console.log(e)
		var subdata = e.detail.value;
		var formcontent = that.data.info.formcontent;
		var record = that.data.record
		var formdata = {};
		for (var i = 0; i < formcontent.length;i++){
			//console.log(subdata['form' + i]);
			if (formcontent[i].val3 == 1 && (subdata['form' + i] === '' || subdata['form' + i] === undefined || subdata['form' + i].length==0)){
					$.alert(formcontent[i].val1+' 必填');return;
			}
			if (formcontent[i].key =='switch'){
					if (subdata['form' + i]==false){
							subdata['form' + i] = '否'
					}else{
							subdata['form' + i] = '是'
					}
			}
			if (formcontent[i].key == 'selector') {
					subdata['form' + i] = formcontent[i].val2[subdata['form' + i]]
			}
			var nowformdata = {};
			formdata[formcontent[i].val1] = subdata['form' + i];
		}
		console.log(formdata)
		$.post("ggk/subinfo/rid/"+record.id,{formcontent:formdata},function(res){
			if(res.status==0){
				$.alert(res.msg)
			}else{
				that.changemaskshow();
				$.success(res.msg);
				that.reLoad();
			}
		})
	}
}))